package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BkHome;
import com.ruoyi.system.service.IBkHomeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页文章列Controller
 * 
 * @author ruoyi
 * @date 2025-01-31
 */
@RestController
@RequestMapping("/bk/home")
public class BkHomeController extends BaseController
{
    @Autowired
    private IBkHomeService bkHomeService;

    /**
     * 查询首页文章列列表
     */
//    @PreAuthorize("@ss.hasPermi('bk:home:list')")
//    未登录访问
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(BkHome bkHome)
    {
        startPage();
        List<BkHome> list = bkHomeService.selectBkHomeList(bkHome);
        return getDataTable(list);
    }

    /**
     * 导出首页文章列列表
     */
    @PreAuthorize("@ss.hasPermi('bk:home:export')")
    @Log(title = "首页文章列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BkHome bkHome)
    {
        List<BkHome> list = bkHomeService.selectBkHomeList(bkHome);
        ExcelUtil<BkHome> util = new ExcelUtil<BkHome>(BkHome.class);
        util.exportExcel(response, list, "首页文章列数据");
    }

    /**
     * 获取首页文章列详细信息
     */
    @PreAuthorize("@ss.hasPermi('bk:home:query')")
    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable("articleId") Long articleId)
    {
        return success(bkHomeService.selectBkHomeByArticleId(articleId));
    }

    /**
     * 新增首页文章列
     */
    @PreAuthorize("@ss.hasPermi('bk:home:add')")
    @Log(title = "首页文章列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BkHome bkHome)
    {
        return toAjax(bkHomeService.insertBkHome(bkHome));
    }

    /**
     * 修改首页文章列
     */
    @PreAuthorize("@ss.hasPermi('bk:home:edit')")
    @Log(title = "首页文章列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BkHome bkHome)
    {
        return toAjax(bkHomeService.updateBkHome(bkHome));
    }

    /**
     * 删除首页文章列
     */
    @PreAuthorize("@ss.hasPermi('bk:home:remove')")
    @Log(title = "首页文章列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable Long[] articleIds)
    {
        return toAjax(bkHomeService.deleteBkHomeByArticleIds(articleIds));
    }
}
